extends KinematicBody2D

var life = 1370
const attack = 100
# 最基本的法术伤害计算公式是：法术伤害 = 法术强度 × 技能系数。例如，一个技能的技能系数是 1.5，角色的法术强度是 100，那么这个技能造成的法术伤害就是 100×1.5 = 150。
var vec = Vector2(-0.25,0)
# 碰撞对象
var kc2d
# 碰撞的植物
var plant 

func _ready():
	self.set_meta("is_zombie", true)
	pass

func _process(delta):
	kc2d = move_and_collide(vec)
	if self.life <= 0:
		queue_free()
	pass

func sub(bullet_type,shanghai):
	$AnimatedSprite.material.set("shader_param/flash_state",1)
	yield(get_tree().create_timer(0.1),"timeout")
	$AnimatedSprite.material.set("shader_param/flash_state",0)
	if bullet_type == "wandou":
		self.life -= shanghai
		$ProgressBar.value -=shanghai
	if bullet_type == "jinweijianguo":
		self.life -= shanghai
		$ProgressBar.value -=shanghai
	#print_debug(self.life)
	
	pass
	
func play_hit():
	$se.play()
	
func play_attack():
	$AnimatedSprite.play("attack")
	
func stop():
	vec.x = 0

func _on_AnimatedSprite_animation_finished():
	if $AnimatedSprite.animation == "attack":
		if is_instance_valid(plant):
			plant.life -= attack
		else:
			$AnimatedSprite.play("walk")
			vec.x = -0.25
		pass
	pass # Replace with function body.
